import React, { Component } from 'react';//直接输入rcc快捷方式
import "../../styles/home/MyHeader.css"//导入并执行css样式
import { withRouter } from "react-router-dom"



class Header extends Component {
    constructor(props) {
        super(props)
        this.state = {
            login: "登录"
        }
    }
    componentDidMount() {
        if (localStorage.getItem("token")) {
            this.setState({ login: "我的" })
        }
    }
    goLogin() {
        if (this.state.login === "我的") {
            this.props.history.push("/index/mine")
        } else {
            this.props.history.push("/login")
        }

    }
    gosearch(){
        this.props.history.push("/search")
    }
    render() {
        return (
            <div className='homeinput-box'>
                <input type="text" placeholder='搜索店内商品' onClick={() => { this.gosearch() }} />
                <span onClick={() => { this.goLogin() }}>{this.state.login}</span>
            </div>
        );
    }
}

export default withRouter(Header);//要想显示必须在根组件渲染